class Solution {
public:
    int jump(vector<int>& nums) {
        int left = 0, right = 0, maxPos = 0;
        int ret = 0;
        while (left <= right)
        {
            if (maxPos >= nums.size() - 1) return ret;

            for (int j = left; j <= right; j++)
            {
                maxPos = max(maxPos, nums[j] + j);
            }
            left = right + 1;
            right = maxPos;
            ret++;
        }

        return -1;
    }
};